package com.gbas.comu.servlet;

import com.gbas.comu.util.EMF;
import com.gbas.comu.util.EntityManagerUtil;

import javax.persistence.EntityManager;
import javax.servlet.*;
import java.io.IOException;

public class ComuFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        EntityManager em = EMF.get().createEntityManager();
        EntityManagerUtil.ENTITY_MANAGERS.set(em);
        chain.doFilter(req, resp);
        EntityManagerUtil.ENTITY_MANAGERS.remove();
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
